<?include './admin/view/header.inc.htm';?>

<div class="panel">
	<div class="header">插件列表</div>
	<div class="body">
		<table class="tlist">
			<? foreach($pluginlist as $dir=>$plugin) { ?>
			<tr valign="top" dir="<?=$dir?>">
				<td width="54"><a href="admin/plugin-read-<?=$dir?>.htm" target="_blank"><img src="<?=$plugin['icon_url']?>" width="54" height="54" /></a></td>
				<td width="200">
					<a href="admin/plugin-read-<?=$dir?>.htm"><b><?=$plugin['name']?> </b></a>v<?=$plugin['version']?>
					<br /><span class="small"><?=$dir?></span>
				</td>
				<td>
					<p class="grey"><?=$plugin['brief']?></p>
				</td>
				<td width="400" align="right">
					<button class="small blue plugin_download_button <?=($plugin['downloaded'] ? 'disabled' : '')?>" <?=($plugin['downloaded'] ? ' style="display: none"' : '')?>>下载</button>
					
					<? if(!empty($plugin['setting_url'])) { ?>
					<button class="small grey plugin_setting_button <?=(!$plugin['installed'] ? 'disabled' : '')?>" onclick="window.location='<?=$plugin['setting_url']?>'"<?=(!$plugin['downloaded'] ? ' style="display: none"' : '')?>>设置</button> 　　　
					<? } ?>
					<button class="small blue plugin_install_button <?=($plugin['installed'] || !$plugin['downloaded'] ? 'disabled' : '')?>" <?=(!$plugin['downloaded'] ? ' style="display: none"' : '')?>>安装</button> 　
					<button class="small red plugin_unstall_button <?=(!$plugin['installed'] || !$plugin['downloaded'] ? 'disabled' : '')?>" <?=(!$plugin['downloaded'] ? ' style="display: none"' : '')?>>卸载</button>
				</td>
			</tr>
			<? } ?>
		</table>
	</div>
</div>
<p class="page"><?=$pages?></p>

<?include './admin/view/footer.inc.htm';?>

<script>
$('button.plugin_install_button').on('click', function() {
	var jtr = $(this).closest('tr');
	var dir = jtr.attr('dir');
	$.xget('plugin/'+dir+'/install.php', function(code, message) {
		if(code == 0) {
			jtr.find('button.plugin_install_button').button('disabled');
			jtr.find('button.plugin_unstall_button').button('reset');
			jtr.find('button.plugin_setting_button').button('reset');
			$.alert('安装成功');
		} else {
			$.alert(message);
		}
	});
});
$('button.plugin_unstall_button').on('click', function() {
	var jtr = $(this).closest('tr');
	var dir = jtr.attr('dir');
	$.xget('plugin/'+dir+'/unstall.php', function(code, message) {
		if(code == 0) {
			jtr.find('button.plugin_install_button').button('reset');
			jtr.find('button.plugin_unstall_button').button('disabled');
			jtr.find('button.plugin_setting_button').button('disabled');
			$.alert('卸载成功');
		} else {
			$.alert(message);
		}
	});
});
$('button.plugin_download_button').on('click', function() {
	var jtr = $(this).closest('tr');
	var dir = jtr.attr('dir');
	$.xget('admin/plugin-download-'+dir+'.htm', function(code, message) {
		if(code == 0) {
			jtr.find('button.plugin_download_button').hide().button('disabled');
			jtr.find('button.plugin_install_button').show().button('reset');
			jtr.find('button.plugin_unstall_button').show().button('disabled');
			jtr.find('button.plugin_setting_button').show().button('disabled');
			$.alert('下载成功');
		} else {
			$.alert(message);
		}
	});
});

</script>